<template>
  <view class="day" :class="[customClass]" :style="customStyle">
    <view
      v-for="(option, index) in options"
      v-show="show"
      :key="index"
      :class="[select === index ? 'sel' : '', 'day-item']"
      @click="handleClick(index)"
    >
      {{ option }}
    </view>
  </view>
</template>

<script>
  export default {
    name: 'SelectableTabs',
    props: {
      // 是否显示组件
      show: {
        type: Boolean,
        default: true
      },
      // 选项数组
      options: {
        type: Array,
        required: true
      },
      // 初始选中索引
      selectedIndex: {
        type: Number,
        default: 0
      },
      // 自定义类名
      customClass: {
        type: String,
        default: ''
      },
      // 自定义内联样式
      customStyle: {
        type: Object,
        default: () => ({})
      }
    },
    data() {
      return {
        select: this.selectedIndex
      };
    },
    watch: {
      selectedIndex(newValue) {
        this.select = newValue;
      }
    },
    methods: {
      handleClick(index) {
        if (this.select !== index) {
          this.select = index;
          this.$emit('update:selectedIndex', index);
          this.$emit('change', index);
        }
      }
    }
  };
</script>

<style scoped>
.day {
  display: flex;
  width: 200rpx;
  height: 30px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #ccc;
  box-sizing: border-box;
  
}

.day-item {
  flex: 1;
  height: 100%;
  line-height: 30px;
  text-align: center;
  color: #333;
  cursor: pointer;
}

.sel {
  background-color: #2196f3;
  color: white;
}

.day-item:first-child {
  border-right: 1px solid rgba(0, 0, 0, 0.1);
}
</style>
